package com.sctlqq.wuye.controller;

import com.sctlqq.wuye.service.impl.QiniuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@RestController
@RequestMapping("/sctlqq/api/wuye/qiniu")
public class QiNiuTestController {

    @Autowired
    private QiniuService qiniuService;

    @PostMapping("/testUpload")
    @ResponseBody
    public String uploadImage(@RequestParam("file") MultipartFile file, HttpServletRequest request) {

        if(file.isEmpty()) {
            return "error";
        }

        try {
            String fileUrl=qiniuService.saveImage(file);
            return fileUrl;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "fail";
    }
}
